import uniqueId from '@form-create/utils/lib/unique';
import {localeProps, makeRequiredRule} from '../../utils';

const label = '单行文本';
const name = 'jd-input';

export default {
    icon: 'icon-input',
    label,
    name,
    rule({t}) {
        return {
            type: 'input',
            field: 'DHWB',
            title: '单行文本',
            info: '',
            $required: false,
            validate: false,
            props: {
                clearable: true,
            }
        };
    },
    watch:{
        'useScript': function(val){
            if (val.value.isScript){
                val.rule.inject = true;
                val.rule.on = val.value._script;
                // 手动注册事件
                //val.rule.on = eval('(function (){return ' + val.value._script + '}())');
                // val.rule.on = {
                //     change: (self, value)=>{
                //         console.log("XXXX");
                //         console.log(new Date().getTime())
                //         console.log('self',self.api.form.DHWB);
                //         console.log('value', value)
                //     }
                // };
            } else{
                val.rule.inject = false;
                val.rule.on = {};
            }
        },
    },
    props(_, {t}) {
        return localeProps(t, name + '.props', [ 
            {type: 'input', field: 'placeholder', title: '占位文本'}, 
            makeRequiredRule(),
            {
                type: 'select',
                field: 'type',
                title: '输入类型',
                hidden: true,
                options: [
                    {label: '单行文本', value: 'text'}, 
                    {label: '多行文本',value: 'textarea'}, 
                    {label: '数字类型', value: 'number'}, 
                    {label: '密码类型', value: 'password'}
                ],
            }, 
            {
                type: 'row',
                props: {gutter: 5},
                children: [
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'JdIconSelect',field: 'prefixIcon',title: '头部图标',style: { width: '200px'}}, 
                        ]
                    },
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'JdIconSelect', field: 'suffixIcon', title: '尾部图标',style: { width: '200px'}}, 
                        ]
                    }
                ]
            },
            {
                type: 'col',
                props: {span: 12},
                children: [
                    {type: 'switch', field: 'showWordLimit', title: '显示字数'}, 
                ]
            },
            {
                type: 'col',
                props: {span: 12},
                children: [
                    {type: 'inputNumber', field: 'maxlength', title: '最大长度', props: {min: 0, max: 500, controlsPosition:'right', width: '100%'}}
                ]
            }, 
            {
                type: 'col',
                props: {span: 12},
                children: [
                    {type: 'switch', field: 'disabled', title: '是否禁用'}, 
                ]
            },
            {
                type: 'col',
                props: {span: 12},
                children: [
                    {type: 'switch', field: 'readonly', title: '是否只读'}, 
                ]
            },
            {type: 'ItemScript', field: 'useScript', value: ''}, 
        ]);
    }
};
